<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../../static/js/jquery.js"></script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>数据统计</li>
        <li>出库统计</li>
        <li>基本内容</li>
    </ul>
</div>
<div class="rightinfo">
    <form action="" method="post" id="warehouseform">
        <ul class="tools">
            <li> 所属区域：
                <select id="province" name="province">
                    <option value="0">请选择省份</option>
                </select>
                <select id="city" name="city">
                    <option value="0">请选择城市</option>
                </select>
            </li>
            <li> 仓库名称:
                <input type="text" id="warehousename" name="warehousename"/>
            </li>
            <li> 时间:
                <input type="date" id="createtime1" name="createtime1"/>--<input type="date" id="createtime2"
                                                                                 name="createtime2"/>
            </li>
            <li class="subBut" id="subBut">
                <img src="../../../static/images/t06.png"/>查询
            </li>
        </ul>
        <table class="tablelist">
            <thead>
            <tr>
                <th>序号</th>
                <th>仓库名称</th>
                <th>负责人</th>
                <th>所属区域</th>
                <th>出库数量</th>
                <th>金额</th>
                <th>出库明细</th>
            </tr>
            </thead>
            <tbody id="warehousetr">
            <tr>
                <td>1</td>
                <td>南京21号仓库</td>
                <td>朱元璋</td>
                <td>江苏南京</td>
                <td>5</td>
                <td>￥9,876,582</td>
                <td>
                    <a href="/statis/delivery/deliveryView" class="tablelink">查看详情</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue" id="totalCount">1256</i>条记录，当前显示第&nbsp;<i class="blue" id="pageNum">2&nbsp;</i>页
            </div>
            <ul class="paginList" id="page">
                <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
                <li class="paginItem"><a href="javascript:;">1</a></li>
                <!--                <li class="paginItem current"><a href="javascript:;">2</a></li>-->
                <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
            </ul>
        </div>
    </form>
</div>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');

    $(function () {

        queryWarehouse();

        queryProvince();

        $("#province").blur(function () {
            var pid = $("#province").val();
            if (pid > 0) {
                $.ajax({
                    type: "post",
                    url: "/sales/city",
                    data: {pid: pid},
                    dataType: "json",
                    success: function (data) {
                        console.log(data)
                        var city = '';
                        city += '<option value="0">请选择城市</option>';
                        for (var i = 0; i < data.data.length; i++) {
                            city += '<option value="' + data.data[i].id + '">' + data.data[i].cname + '</option>';
                        }
                        $("#city").html(city);
                    },
                    error: function () {
                        alert("查询城市失败！");
                    }
                })
            } else {
                city += '<option value="0">请选择城市</option>';
                $("#city").html(city);
            }
        });

        $("#subBut").click(function () {
            queryWarehouse();
        });
    })

    function queryProvince() {
        $.ajax({
            type: "post",
            url: "/sales/province",
            data: {},
            dataType: "json",
            success: function (data) {
                console.log(data)
                var province = '';
                province += '<option value="0">请选择省份</option>';
                for (var i = 0; i < data.data.length; i++) {
                    province += '<option value="' + data.data[i].id + '">' + data.data[i].pname + '</option>';
                }
                $("#province").html(province);
            },
            error: function () {
                alert("查询省份失败！");
            }
        });
    }

    function queryWarehouse(pageNum) {
        let province = $("#province option:selected").val();
        // console.log(province);
        let city = $("#city option:selected").val();
        // console.log(city);
        let cnamelike = $("#warehousename").val();
        // console.log(warehousenamelike);
        let createtime1 = $("#createtime1").val();
        // console.log(createtime1);
        let createtime2 = $("#createtime2").val();
        // console.log(createtime2);
        $.ajax({
            url: "/delivery/warehouse",
            method: "post",
            dataType: "json",
            data: {
                pageNum: pageNum,
                province: province,
                city: city,
                cnamelike: cnamelike,
                createtime1: createtime1,
                createtime2: createtime2
            },
            success: function (data) {
                console.log(data);
                var str = '';
                var da = data.data.data;
                for (var i = 0; i < da.length; i++) {
                    var total = 0;
                    for (var j = 0; j < da[i].ckWarehouses.length; j++) {
                        for (var k = 0; k < da[i].ckWarehouses[j].orderDetails.length; k++) {
                            total += da[i].ckWarehouses[j].orderDetails[k].prototal;
                        }
                    }
                    str += '<tr>\n' +
                        '                <td>' + (i + ((data.data.pageNum - 1) * data.data.pageSize) + 1) + '</td>\n' +
                        '                <td>' + da[i].cname + '</td>\n' +
                        '                <td>' + da[i].user.uname + '</td>\n' +
                        '                <td>' + da[i].province.pname + da[i].city.cname + '</td>\n' +
                        '                <td>' + da[i].ckWarehouses.length + '</td>\n' +
                        '                <td>￥' + total + '</td>\n' +
                        '                <td>\n' +
                        '                    <a href="/statis/delivery/deliveryView?id=' + da[i].id + '" class="tablelink">查看详情</a>\n' +
                        '                </td>\n' +
                        '            </tr>';
                }
                $("#warehousetr").html(str);
                $("#totalCount").html(data.data.totalCount);
                $("#pageNum").html(data.data.pageNum);
                var begin = data.data.pageNum - 5;
                var end = data.data.pageNum + 4;
                if (begin < 1) {
                    begin = 1;
                    if (data.data.totalPage < 10) {
                        end = data.data.totalPage;
                    } else {
                        end = 10;
                    }
                }
                if (end > data.data.totalPage) {
                    end = data.data.totalPage;
                    if (begin < 0) {
                        begin = 1;
                    }
                }
                var page = '';
                page += '<li class="paginItem" id="up"><a onclick="queryWarehouse(' + (data.data.pageNum - 1) + ')"><span class="pagepre"></span></a></li>\n';
                for (var i = begin; i <= end; i++) {
                    if (i == data.data.pageNum) {
                        page += '<li class="paginItem current"><a onclick="queryWarehouse(' + i + ')">' + i + '</a></li>';
                    } else {
                        page += '<li class="paginItem"><a onclick="queryWarehouse(' + i + ')">' + i + '</a></li>';
                    }
                }
                page += '<li class="paginItem" id="down"><a onclick="queryWarehouse(' + (data.data.pageNum + 1) + ')"><span class="pagenxt"></span></a></li>';
                $("#page").html(page);

                if (data.data.pageNum == 1) {
                    // $("#up").removeAttr("onclick");
                    $("#up").attr("disabled", true).css("pointer-events", "none")
                }
                if (data.data.pageNum == data.data.totalPage) {
                    // $("#down").removeAttr("onclick");
                    $("#down").attr("disabled", true).css("pointer-events", "none")
                }
            },
            error: function () {
                alert("查询仓库失败!");
            }
        });
    }

</script>
</body>
</html>
